package com.poetize.plus.controller.ui;

import com.poetize.plus.entity.dto.BarrageDTO;
import com.poetize.plus.entity.vo.BarrageVO;
import com.poetize.plus.service.BarrageService;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zuosy
 * @created 2024/4/10 14:25
 */
@Tag(name = "弹幕操作")
@RestController
@RequestMapping("/barrage")
@RequiredArgsConstructor
public class BarrageUiController {

    private final BarrageService barrageService;

    @PostMapping("/sendBarrage")
    @Operation(summary = "发送弹幕")
    @PreAuthorize(value = "hasAnyRole('common','administrator')")
    public R<Long> sendBarrage(@RequestBody @Validated BarrageDTO barrageDTO){
        return R.ok(barrageService.sendBarrage(barrageDTO));
    }

    @PermitAll
    @GetMapping("/getBarrageList")
    @Operation(summary = "获取弹幕")
    public R<List<BarrageVO>> getBarrageList(){
        return R.ok(barrageService.getBarrageList());
    }
}
